package com.ruoyi.web.controller.course;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.Course;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.ICourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *  课程信息
 * */
@RestController
@RequestMapping("/course")
public class CourseController extends BaseController {
    @Autowired
    private ICourseService courseService;
    @Log(title = "课程列表", businessType = BusinessType.OTHER)
    @RequestMapping("/list")
    public TableDataInfo listCourse(Course course){
        startPage();
        List<Course> list = courseService.selectCourseList(course);
        return getDataTable(list);
    }
    @Log(title = "课程信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult addCourse(@Validated @RequestBody Course course){
        course.setCreateBy(getUsername());
        return toAjax(courseService.insertCourse(course));
    }
    @Log(title = "删除课程", businessType = BusinessType.DELETE)
    @RequestMapping("/delete/{courseId}")
    public AjaxResult deleteCourse(@PathVariable Long courseId){
        return toAjax(courseService.deleteCourseById(courseId));
    }
    @Log(title = "删除课程", businessType = BusinessType.DELETE)
    @PostMapping("/batchDelete")
    public AjaxResult deleteCourseByIds(@RequestBody Long[] courseIds){
        return toAjax(courseService.deleteCourseByIds(courseIds));
    }
    /**
     * 更新课程信息
     * @param course
     * @return 结果
     * */
    @RequestMapping("/update")
    public AjaxResult updateCourse(Course course){
        return AjaxResult.success(courseService.updateCourse(course));
    }



}
